import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:i18n_demo/GYLocalizeationsDeelgate.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Flutter Demo",
      home: GYHomePage(),
      // 指定哪些widget需要国际化
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,//指定本地的字符串和一些其它的值
        GlobalCupertinoLocalizations.delegate,//对应的Cupertino风格
        GlobalWidgetsLocalizations.delegate,//指定默认的文本排列方向, 由左到右或由右到左
        GYLocalizeationsDelegate.delegate, //自定义delegate
      ],
      //支持哪些语言国际化的集合
      supportedLocales: getLanguageCode(),
    );
  }

/*  根据语言code设置值*/
  List<Locale> getLanguageCode() {
    return [
      Locale("zh"),
      Locale("en"),
    ];
  }

  /*指定 语言代码、文字代码和国家代码， 来配置语言国际化*/
  List<Locale> getConuntryCode() {
    return [ const Locale.fromSubtags(languageCode: 'zh'), // generic Chinese 'zh'
    const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'), // generic simplified Chinese 'zh_Hans'
    const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'), // generic traditional Chinese 'zh_Hant'
    const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN'), // 'zh_Hans_CN'
    const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'TW'), // 'zh_Hant_TW'
    const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'HK'), // 'zh_Hant_HK'
    ];
  }
}

class GYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(title: Text("首页"),),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("国际化测试", style: TextStyle(fontSize: 25)),
            ElevatedButton(
              child: Text("您好，世界", style: TextStyle(fontSize: 25),),
              onPressed: () {
                showDatePicker(
                  context: context,
                  initialDate: DateTime.now(),
                  firstDate: DateTime(2000),
                  lastDate: DateTime(3000),
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}